from sys import argv    # 在sys库中调用一个参数argv

script, input_file = argv    # 定义argv

def print_all(f):    # 定义一个函数 print_all
    print (f.read())    # 以可读形式输出函数

def rewind(f):
    f.seek(0)    # 转到第一个字节

def print_a_line (line_count, f):    # 定义一个有两个参数的函数
    print(line_count, f.readline())    # 输出行号，按行读取的内容

current_file = open (input_file)    # 定义打开的文件为current_file

print("First let's print the whole file:\n")

print_all(current_file)    # 全部读取

print("Now let's rewind, kind of like a tape.")

rewind (current_file)    # 转到第一个字节

print("Let's print three lines:")

current_line = 1
print_a_line(current_line, current_file)    # print第一行，和内容

current_line = current_line + 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)
